package com.easthome.service.impl;

import com.easthome.entity.PageResult;
import com.easthome.entity.QueryPageBean;
import com.easthome.mapper.CheckItemMapper;
import com.easthome.pojo.CheckItem;
import com.easthome.service.CheckItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * 接收新增检查项请求
     * 接收请求参数checkItem
     */
    @Override
    public int addCheckItem(CheckItem checkItem) {
        return checkItemMapper.addCheckItem(checkItem);
    }

    /**
     * 查询所有的检查项
     */
    @Override
    public List<CheckItem> queryAllCheckItem() {
        return checkItemMapper.queryAllCheckItem();
    }

    /**
     * 分页查询 查询检查项目
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult queryCheckItemPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<CheckItem> page = checkItemMapper.queryCheckItemPage(queryPageBean.getQueryString());
        PageResult pageResult = new PageResult();
        pageResult.setTotal(page.getTotal());
        pageResult.setRows(page.getResult());
        return pageResult;
    }


    /**
     * 删除检查项数据
     * 参数是主键
     *
     * @param id
     * @return
     */
    @Override
    public int deleteCheckItem(Integer id) {
        return checkItemMapper.deleteCheckItem(id);
    }

    /**
     * 检查项查询 参数是主键
     *
     * @param id
     * @return
     */
    @Override
    public CheckItem queryCheckItemById(Integer id) {
        return checkItemMapper.queryCheckItemById(id);
    }

    /**
     * 接收检查项数据的修改
     * 参数是检查项对象
     */
    @Override
    public int editCheckItem(CheckItem checkItem) {
        return checkItemMapper.editCheckItem(checkItem);
    }
}
